package com.teamwork.module01.controller;

import com.teamwork.common.entity.module01.Class;
import com.teamwork.common.entity.module01.Subject;
import com.teamwork.common.result.Result;
import com.teamwork.module01.service.SubjectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/mod01/subject")
public class SubjectController {
    @Resource
    private SubjectService subjectService;



    @GetMapping("/getbyname")
    public Result getByname(String name){
        return subjectService.getByName(name);
    }
    @GetMapping("/page")
    public Result page(Integer page,Integer size){
        return subjectService.getPage(page,size);
    }
    @PostMapping
    public Result InsertOrUpdate(@RequestBody Subject subject){
        return subjectService.InsertOrUpdate(subject);
    }

    @DeleteMapping
    public Result batchDelete(@RequestBody Map<String,Integer[]> map){
        Integer[] ids = map.get("ids");
        List<Integer> idList = Arrays.asList(ids);
        return subjectService.batchDelete(idList);
    }
}
